package com.swpu.zdl.controller;

import com.swpu.zdl.pojo.Teacher;
import com.swpu.zdl.service.TeacherService;
import com.swpu.zdl.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/teacher")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;
    // 获取全部老师信息
    @GetMapping("/getAll")
    public Result getAll(){
        List<Teacher> teachers = teacherService.getAll();
        return new Result(200, "所有老师信息", teachers);
    }
    // 添加老师
    @PostMapping("/addTeacher")
    public Result addTeacher(@RequestBody Teacher teacher){
        if (!teacherService.addTeacher(teacher)){
            return new Result(500, "添加老师失败");
        }
        return new Result(200, "添加老师成功");
    }
    // 删除老师
    @DeleteMapping("/deleteTeacher/{gongHao}")
    public Result deleteTeacher(@PathVariable String gongHao){
        if (!teacherService.deleteTeacher(gongHao)){
            return new Result(500, "删除老师失败");
        }
        return new Result(200, "删除老师成功");
    }
    // 修改老师信息
    @PutMapping("/updateTeacher/{gongHao}")
    public Result updateTeacher(@PathVariable String gongHao, @RequestBody Teacher teacher){
        if (!teacherService.updateTeacher(gongHao, teacher)){
            return new Result(500, "修改老师信息失败");
        }
        return new Result(200, "修改老师信息成功");
    }
    // 查看当前老师所教的课程
    @GetMapping("/getTeacherKp")
    public Result getTeacherKp(String gongHao){
        Teacher teacher  = teacherService.getTeacherKp(gongHao);
        return new Result(200, "当前老师所教的课程", teacher);
    }

}
